<?php

namespace App\Admin\Actions\Slide;

use App\Library\Logic\OperateLogLogic;
use App\Models\SlideModel;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Actions\Response;
use Encore\Admin\Facades\Admin;

class SlideDeleteAction extends RowAction
{
    public $name = '删除';

    /**
     *
     * @param SlideModel $model
     * @return Response
     *
     */
    public function handle(SlideModel $model): Response
    {
        if (is_null($model)) return $this->response()->error(__('errorCode.433'))->refresh();
        $model->deleted_at = now();
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.slide.delete');
        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog(): void
    {
        $this->confirm('确定删除吗?');
    }
}
